package LeetCode.month01.day30;

import java.util.Arrays;

public class No2779 {
    public int maximumBeauty(int[] nums, int k) {
        Arrays.sort(nums);
        int n = nums.length;
        int res = 0;
        int left = 0;
        for (int i = 0; i < n; i++) {
            while(nums[i]-nums[left]>2*k){
                left++;
            }
            res = Math.max(res,i-left+1);
        }
        return res;
    }
}
